

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
    <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="z">
  <meta name="keywords" content="go,go实现阿里云DDNS">
  
    <meta name="description" content="一、背景阿里云域名解析到动态ip，如：外网访问家庭网络  二、思路 有个配置文件配置一些参数 自动获取公网ip，阿里云解析ip，对比不一致更新ip  三、代码1、配置文件 conf.ini1234567891011121314[aliyun]# 阿里云的AccessKeyIdaccessKeyId&#x3D;XX# 阿里云的AccessKeySecretaccessKeySecret&#x3D;XX[domain]#">
<meta property="og:type" content="article">
<meta property="og:title" content="go实现阿里云DDNS">
<meta property="og:url" content="https://hexo.xy94.top/2022/go%E5%AE%9E%E7%8E%B0%E9%98%BF%E9%87%8C%E4%BA%91DDNS.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="一、背景阿里云域名解析到动态ip，如：外网访问家庭网络  二、思路 有个配置文件配置一些参数 自动获取公网ip，阿里云解析ip，对比不一致更新ip  三、代码1、配置文件 conf.ini1234567891011121314[aliyun]# 阿里云的AccessKeyIdaccessKeyId&#x3D;XX# 阿里云的AccessKeySecretaccessKeySecret&#x3D;XX[domain]#">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2022-09-22T00:34:27.000Z">
<meta property="article:modified_time" content="2024-02-20T07:39:15.824Z">
<meta property="article:author" content="z">
<meta property="article:tag" content="go">
<meta property="article:tag" content="ddns">
<meta name="twitter:card" content="summary_large_image">
  
  
  
  <title>go实现阿里云DDNS - Hexo</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"hexo.xy94.top","root":"/","version":"1.9.7","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":{"measurement_id":null},"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml","include_content_in_search":true};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.3.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>个人分享</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/" target="_self">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/" target="_self">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/" target="_self">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/" target="_self">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/" target="_self">
                <i class="iconfont icon-user-fill"></i>
                <span>联系我</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/links/" target="_self">
                <i class="iconfont icon-link-fill"></i>
                <span>友链</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item dropdown">
              <a class="nav-link dropdown-toggle" target="_self" href="javascript:;" role="button"
                 data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                <i class="iconfont icon-books"></i>
                <span>文档</span>
              </a>
              <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                
                  
                  
                  
                  <a class="dropdown-item" href="https://hexo.fluid-dev.com/" target="_self">
                    
                    <span>主题博客</span>
                  </a>
                
                  
                  
                  
                  <a class="dropdown-item" href="https://hexo.fluid-dev.com/docs/guide/" target="_self">
                    
                    <span>配置指南</span>
                  </a>
                
                  
                  
                  
                  <a class="dropdown-item" href="https://hexo.fluid-dev.com/docs/icon/" target="_self">
                    
                    <span>图标用法</span>
                  </a>
                
              </div>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="go实现阿里云DDNS"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        z
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-09-22 08:34" pubdate>
          2022-09-22 08:34:27 星期四 早上
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          <!-- compatible with older versions-->
          1.4k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          <!-- compatible with older versions-->
          12 分钟
        
      </span>
    

    
    
      
        <span id="leancloud-page-views-container" class="post-meta" style="display: none">
          <i class="iconfont icon-eye" aria-hidden="true"></i>
          <span id="leancloud-page-views"></span> 次
        </span>
        
      
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>
<meta name="baidu-site-verification" content="codeva-jcIBX7fHxH" />
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <h1 id="seo-header">go实现阿里云DDNS</h1>
            
            
              <div class="markdown-body">
                
                <h1 id="一、背景"><a href="#一、背景" class="headerlink" title="一、背景"></a>一、背景</h1><pre><code class="hljs">阿里云域名解析到动态ip，如：外网访问家庭网络
</code></pre>
<h1 id="二、思路"><a href="#二、思路" class="headerlink" title="二、思路"></a>二、思路</h1><ul>
<li>有个配置文件配置一些参数</li>
<li>自动获取公网ip，阿里云解析ip，对比不一致更新ip</li>
</ul>
<h1 id="三、代码"><a href="#三、代码" class="headerlink" title="三、代码"></a>三、代码</h1><h2 id="1、配置文件-conf-ini"><a href="#1、配置文件-conf-ini" class="headerlink" title="1、配置文件 conf.ini"></a>1、配置文件 conf.ini</h2><figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs ini"><span class="hljs-section">[aliyun]</span><br><span class="hljs-comment"># 阿里云的AccessKeyId</span><br><span class="hljs-attr">accessKeyId</span>=XX<br><span class="hljs-comment"># 阿里云的AccessKeySecret</span><br><span class="hljs-attr">accessKeySecret</span>=XX<br><br><span class="hljs-section">[domain]</span><br><span class="hljs-comment"># 域名列表，多个用逗号隔开 </span><br><span class="hljs-attr">domainList</span>=@.demo.top,*.demo.top,hexo.demo.top<br><br><span class="hljs-section">[local]</span><br><span class="hljs-comment"># 设定固定IP，用于IP固定不变或手动更新</span><br><span class="hljs-comment">#ip=0.0.0.0</span><br><br></code></pre></td></tr></table></figure>

<h2 id="2、程序代码-main-go"><a href="#2、程序代码-main-go" class="headerlink" title="2、程序代码 main.go"></a>2、程序代码 main.go</h2><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br></pre></td><td class="code"><pre><code class="hljs go"><span class="hljs-keyword">package</span> main<br><br><span class="hljs-keyword">import</span> (<br>	<span class="hljs-string">&quot;encoding/json&quot;</span><br>	<span class="hljs-string">&quot;errors&quot;</span><br>	<span class="hljs-string">&quot;fmt&quot;</span><br>	<span class="hljs-string">&quot;io&quot;</span><br>	<span class="hljs-string">&quot;log&quot;</span><br>	<span class="hljs-string">&quot;net&quot;</span><br>	<span class="hljs-string">&quot;net/http&quot;</span><br>	<span class="hljs-string">&quot;os&quot;</span><br>	<span class="hljs-string">&quot;path/filepath&quot;</span><br>	<span class="hljs-string">&quot;strings&quot;</span><br>	<span class="hljs-string">&quot;time&quot;</span><br><br>	alidnsClient <span class="hljs-string">&quot;github.com/alibabacloud-go/alidns-20150109/v4/client&quot;</span><br>	openapi <span class="hljs-string">&quot;github.com/alibabacloud-go/darabonba-openapi/v2/client&quot;</span><br>	util <span class="hljs-string">&quot;github.com/alibabacloud-go/tea-utils/v2/service&quot;</span><br>	<span class="hljs-string">&quot;github.com/alibabacloud-go/tea/tea&quot;</span><br>	<span class="hljs-string">&quot;gopkg.in/ini.v1&quot;</span><br>)<br><br><span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span> &#123;<br>	ticker := time.NewTicker(<span class="hljs-number">300</span> * time.Second)<br>	<span class="hljs-keyword">defer</span> ticker.Stop()<br>	_main()<br>	<span class="hljs-keyword">for</span> <span class="hljs-keyword">range</span> ticker.C &#123;<br>		fmt.Println(<span class="hljs-string">&quot;执行的业务逻辑&quot;</span>)<br>		_main()<br>	&#125;<br>&#125;<br><span class="hljs-function"><span class="hljs-keyword">func</span> _<span class="hljs-title">main</span><span class="hljs-params">()</span></span> &#123;<br>	fmt.Println(os.Getenv(<span class="hljs-string">&quot;CLASSPATH&quot;</span>))<br>	domain := <span class="hljs-string">&quot;xy94.top&quot;</span><br><br>	ips, err := net.LookupIP(domain)<br>	<span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> &#123;<br>		fmt.Println(<span class="hljs-string">&quot;获取IP地址失败：&quot;</span>, err)<br>		<span class="hljs-keyword">return</span><br>	&#125;<br><br>	<span class="hljs-keyword">for</span> _, ip := <span class="hljs-keyword">range</span> ips &#123;<br>		fmt.Println(<span class="hljs-string">&quot;域名IP:&quot;</span>, ip.String())<br>	&#125;<br>	<span class="hljs-comment">// 获取当前工作目录</span><br>	currentDir, err := os.Getwd()<br>	<span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> &#123;<br>		fmt.Println(<span class="hljs-string">&quot;获取当前工作目录失败：&quot;</span>, err)<br>		<span class="hljs-keyword">return</span><br>	&#125;<br><br>	<span class="hljs-comment">// 配置文件名</span><br>	configFileName := <span class="hljs-string">&quot;conf.ini&quot;</span><br><br>	<span class="hljs-comment">// 构建配置文件路径</span><br>	configPath := filepath.Join(currentDir, configFileName)<br><br>	<span class="hljs-comment">// 打开配置文件</span><br>	cfg, err := ini.Load(configPath)<br>	<span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> &#123;<br>		fmt.Println(<span class="hljs-string">&quot;打开配置文件失败：&quot;</span>, err)<br>		<span class="hljs-keyword">return</span><br>	&#125;<br>	<span class="hljs-comment">// 读取配置文件中的值</span><br>	section, err := cfg.GetSection(<span class="hljs-string">&quot;local&quot;</span>)<br>	<span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> &#123;<br>		fmt.Println(<span class="hljs-string">&quot;获取配置文件section local失败：&quot;</span>, err)<br>		<span class="hljs-keyword">return</span><br>	&#125;<br><br>	ip := section.Key(<span class="hljs-string">&quot;ip&quot;</span>).String()<br><br>	<span class="hljs-comment">// 输出配置文件中的accessKeyId值</span><br>	<span class="hljs-keyword">if</span> ip == <span class="hljs-string">&quot;&quot;</span> &#123;<br><br>		netIP, err := GetWanIpAddress()<br>		<span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> &#123;<br>			fmt.Println(err)<br>		&#125;<br>		ip = *netIP<br>		fmt.Println(ip)<br>	&#125; <span class="hljs-keyword">else</span> &#123;<br><br>		fmt.Println(<span class="hljs-string">&quot;local IP:&quot;</span>, ip)<br>	&#125;<br><br>	<span class="hljs-keyword">if</span> ips[<span class="hljs-number">0</span>].String() != ip &#123;<br>		fmt.Println(<span class="hljs-string">&quot;域名解析IP和本地不一致&quot;</span>)<br><br>		<span class="hljs-comment">// 读取配置文件中的值</span><br>		section, err = cfg.GetSection(<span class="hljs-string">&quot;aliyun&quot;</span>)<br>		<span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> &#123;<br>			fmt.Println(<span class="hljs-string">&quot;获取配置文件section aliyun失败：&quot;</span>, err)<br>			<span class="hljs-keyword">return</span><br>		&#125;<br><br>		accessKeyId := section.Key(<span class="hljs-string">&quot;accessKeyId&quot;</span>).String()<br><br>		<span class="hljs-comment">// 输出配置文件中的accessKeyId值</span><br>		<span class="hljs-comment">// fmt.Println(accessKeyId)</span><br><br>		accessKeySecret := section.Key(<span class="hljs-string">&quot;accessKeySecret&quot;</span>).String()<br><br>		<span class="hljs-comment">// 输出配置文件中的值</span><br>		<span class="hljs-comment">// fmt.Println(accessKeySecret)</span><br><br>		section, err = cfg.GetSection(<span class="hljs-string">&quot;domain&quot;</span>)<br>		<span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> &#123;<br>			fmt.Println(<span class="hljs-string">&quot;获取配置文件section domain失败：&quot;</span>, err)<br>			<span class="hljs-keyword">return</span><br>		&#125;<br><br>		domainList := section.Key(<span class="hljs-string">&quot;domainList&quot;</span>).String()<br><br>		<span class="hljs-comment">// 输出配置文件中的domainList值</span><br>		fmt.Println(domainList)<br><br>		client, _ := CreateClient(tea.String(accessKeyId), tea.String(accessKeySecret))<br><br>		<span class="hljs-comment">// 以逗号隔开获取域名列表</span><br>		domainNameList := strings.Split(domainList, <span class="hljs-string">&quot;,&quot;</span>)<br>		dnsDomainList, _err := GetAllDomainList(client)<br>		fmt.Println(<span class="hljs-string">&quot;阿里云解析内容:&quot;</span>, dnsDomainList)<br>		<span class="hljs-keyword">if</span> _err != <span class="hljs-literal">nil</span> &#123;<br>			fmt.Println(_err)<br>		&#125;<br>		<span class="hljs-comment">// 遍历所有需要同步DNS的域名，查询到他的二级域名</span><br>		<span class="hljs-keyword">for</span> _, domainName := <span class="hljs-keyword">range</span> domainNameList &#123;<br>			fmt.Println(<span class="hljs-string">&quot;处理:&quot;</span>, domainName)<br><br>			<span class="hljs-keyword">for</span> _, dnsDomain := <span class="hljs-keyword">range</span> *dnsDomainList &#123;<br>				<span class="hljs-keyword">if</span> fmt.Sprintf(<span class="hljs-string">&quot;%s%s%s&quot;</span>, *dnsDomain.RR, <span class="hljs-string">&quot;.&quot;</span>, *dnsDomain.DomainName) == domainName &#123;<br><br>					fmt.Println(fmt.Sprintf(<span class="hljs-string">&quot;%s%s%s&quot;</span>, *dnsDomain.RR, <span class="hljs-string">&quot;.&quot;</span>, *dnsDomain.DomainName))<br>					fmt.Println(*dnsDomain.RecordId)<br>					<span class="hljs-keyword">if</span> fmt.Sprintf(<span class="hljs-string">&quot;%s&quot;</span>, *dnsDomain.Value) != ip &#123;<br>						fmt.Println(<span class="hljs-string">&quot;开始更新：&quot;</span>, fmt.Sprintf(<span class="hljs-string">&quot;%s%s%s&quot;</span>, *dnsDomain.RR, <span class="hljs-string">&quot;.&quot;</span>, *dnsDomain.DomainName))<br>						fmt.Println(<span class="hljs-string">&quot;原IP:&quot;</span>, fmt.Sprintf(<span class="hljs-string">&quot;%s&quot;</span>, *dnsDomain.Value))<br>						fmt.Println(<span class="hljs-string">&quot;更新为IP:&quot;</span>, ip)<br>						err = updateDomainRecord(client, fmt.Sprintf(<span class="hljs-string">&quot;%s&quot;</span>, *dnsDomain.RecordId), ip, fmt.Sprintf(<span class="hljs-string">&quot;%s&quot;</span>, *dnsDomain.RR))<br>						<span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> &#123;<br>							<span class="hljs-built_in">panic</span>(err)<br>						&#125;<br>					&#125;<br><br>					<span class="hljs-keyword">break</span><br>				&#125;<br>			&#125;<br>		&#125;<br><br>	&#125;<br><br>	fmt.Println(<span class="hljs-string">&quot;完毕&quot;</span>)<br>&#125;<br><br><span class="hljs-keyword">var</span> result *alidnsClient.Client<br><br><span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">CreateClient</span><span class="hljs-params">(accessKeyId *<span class="hljs-type">string</span>, accessKeySecret *<span class="hljs-type">string</span>)</span></span> (_result *alidnsClient.Client, _err <span class="hljs-type">error</span>) &#123;<br>	<span class="hljs-keyword">if</span> result != <span class="hljs-literal">nil</span> &#123;<br>		<span class="hljs-keyword">return</span> result, _err<br>	&#125;<br>	config := &amp;openapi.Config&#123;<br>		<span class="hljs-comment">// 必填，您的 AccessKey ID</span><br>		AccessKeyId: accessKeyId,<br>		<span class="hljs-comment">// 必填，您的 AccessKey Secret</span><br>		AccessKeySecret: accessKeySecret,<br>	&#125;<br>	<span class="hljs-comment">// Endpoint 请参考 https://api.aliyun.com/product/Alidns</span><br>	config.Endpoint = tea.String(<span class="hljs-string">&quot;alidns.cn-hangzhou.aliyuncs.com&quot;</span>)<br>	_result = &amp;alidnsClient.Client&#123;&#125;<br>	_result, _err = alidnsClient.NewClient(config)<br>	result = _result<br>	<span class="hljs-keyword">return</span> _result, _err<br>&#125;<br><br><span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">updateDomainRecord</span><span class="hljs-params">(client *alidnsClient.Client, rid <span class="hljs-type">string</span>, ip <span class="hljs-type">string</span>, rr <span class="hljs-type">string</span>)</span></span> (_err <span class="hljs-type">error</span>) &#123;<br><br>	updateDomainRecordRequest := &amp;alidnsClient.UpdateDomainRecordRequest&#123;<br>		RecordId: tea.String(rid),<br>		Type:     tea.String(<span class="hljs-string">&quot;A&quot;</span>),<br>		Value:    tea.String(ip),<br>		RR:       tea.String(rr),<br>	&#125;<br>	runtime := &amp;util.RuntimeOptions&#123;&#125;<br>	tryErr := <span class="hljs-function"><span class="hljs-keyword">func</span><span class="hljs-params">()</span></span> (_e <span class="hljs-type">error</span>) &#123;<br>		<span class="hljs-keyword">defer</span> <span class="hljs-function"><span class="hljs-keyword">func</span><span class="hljs-params">()</span></span> &#123;<br>			<span class="hljs-keyword">if</span> r := tea.Recover(<span class="hljs-built_in">recover</span>()); r != <span class="hljs-literal">nil</span> &#123;<br>				_e = r<br>			&#125;<br>		&#125;()<br>		fmt.Println(updateDomainRecordRequest)<br>		<span class="hljs-comment">// 复制代码运行请自行打印 API 的返回值</span><br>		_, _err = client.UpdateDomainRecordWithOptions(updateDomainRecordRequest, runtime)<br>		<span class="hljs-keyword">if</span> _err != <span class="hljs-literal">nil</span> &#123;<br>			<span class="hljs-keyword">return</span> _err<br>		&#125;<br>		fmt.Println(<span class="hljs-string">&quot;更新成功&quot;</span>)<br><br>		<span class="hljs-keyword">return</span> <span class="hljs-literal">nil</span><br>	&#125;()<br><br>	<span class="hljs-keyword">if</span> tryErr != <span class="hljs-literal">nil</span> &#123;<br>		<span class="hljs-keyword">var</span> <span class="hljs-type">error</span> = &amp;tea.SDKError&#123;&#125;<br>		<span class="hljs-keyword">if</span> _t, ok := tryErr.(*tea.SDKError); ok &#123;<br>			<span class="hljs-type">error</span> = _t<br>		&#125; <span class="hljs-keyword">else</span> &#123;<br>			<span class="hljs-type">error</span>.Message = tea.String(tryErr.Error())<br>		&#125;<br>		<span class="hljs-comment">// 错误 message</span><br>		fmt.Println(tea.StringValue(<span class="hljs-type">error</span>.Message))<br>		<span class="hljs-comment">// 诊断地址</span><br>		<span class="hljs-keyword">var</span> data <span class="hljs-keyword">interface</span>&#123;&#125;<br>		d := json.NewDecoder(strings.NewReader(tea.StringValue(<span class="hljs-type">error</span>.Data)))<br>		d.Decode(&amp;data)<br>		<span class="hljs-keyword">if</span> m, ok := data.(<span class="hljs-keyword">map</span>[<span class="hljs-type">string</span>]<span class="hljs-keyword">interface</span>&#123;&#125;); ok &#123;<br>			recommend, _ := m[<span class="hljs-string">&quot;Recommend&quot;</span>]<br>			fmt.Println(recommend)<br>		&#125;<br>		_, _err = util.AssertAsString(<span class="hljs-type">error</span>.Message)<br>		<span class="hljs-keyword">if</span> _err != <span class="hljs-literal">nil</span> &#123;<br>			<span class="hljs-keyword">return</span> _err<br>		&#125;<br>	&#125;<br>	<span class="hljs-keyword">return</span> _err<br>&#125;<br><br><span class="hljs-comment">// GetAllDomainList 获得所有的域名列表</span><br><span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">GetAllDomainList</span><span class="hljs-params">(client *alidnsClient.Client)</span></span> (*[]alidnsClient.DescribeDomainRecordsResponseBodyDomainRecordsRecord, <span class="hljs-type">error</span>) &#123;<br>	<span class="hljs-comment">// 域名解表的结果</span><br>	<span class="hljs-keyword">var</span> domainList []alidnsClient.DescribeDomainRecordsResponseBodyDomainRecordsRecord<br><br>	<span class="hljs-comment">// 当前页码</span><br>	<span class="hljs-keyword">var</span> currentPageNum <span class="hljs-type">int32</span> = <span class="hljs-number">1</span><br>	<span class="hljs-keyword">for</span> &#123;<br>		<span class="hljs-comment">// 请求参数</span><br>		describeDomainRecordsRequest := &amp;alidnsClient.DescribeDomainRecordsRequest&#123;<br>			DomainName: tea.String(<span class="hljs-string">&quot;xy94.top&quot;</span>),<br>			Status:     tea.String(<span class="hljs-string">&quot;Enable&quot;</span>),<br>		&#125;<br>		runtime := &amp;util.RuntimeOptions&#123;&#125;<br>		<span class="hljs-comment">// 请求获取域名列表</span><br>		request, err := result.DescribeDomainRecordsWithOptions(describeDomainRecordsRequest, runtime)<br>		<span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> &#123;<br>			<span class="hljs-keyword">return</span> <span class="hljs-literal">nil</span>, err<br>		&#125;<br>		<span class="hljs-comment">// 遍历并将所有域名放入切片</span><br>		<span class="hljs-keyword">for</span> _, domain := <span class="hljs-keyword">range</span> request.Body.DomainRecords.Record &#123;<br>			domainList = <span class="hljs-built_in">append</span>(domainList, *domain)<br>		&#125;<br>		<span class="hljs-comment">// 判断是否要继续分页</span><br>		<span class="hljs-keyword">if</span> <span class="hljs-type">int</span>(*request.Body.TotalCount) &lt;= <span class="hljs-built_in">len</span>(domainList)+<span class="hljs-number">1</span> &#123;<br>			<span class="hljs-comment">// 查询到现在的域名数量大于等于总域名数量，那么我们就跳出循环</span><br>			<span class="hljs-keyword">break</span><br>		&#125;<br>		<span class="hljs-comment">// 继续循环，页码+1</span><br>		currentPageNum++<br>	&#125;<br>	<span class="hljs-keyword">return</span> &amp;domainList, <span class="hljs-literal">nil</span><br>&#125;<br><br><span class="hljs-comment">// WanIpResponse 请求获取公网IP地址返回的json结果</span><br><span class="hljs-keyword">type</span> WanIpResponse <span class="hljs-keyword">struct</span> &#123;<br>	Ip <span class="hljs-type">string</span> <span class="hljs-string">`json:&quot;ip&quot;`</span><br>&#125;<br><br><span class="hljs-comment">// GetWanIpAddress 获取公网IP地址</span><br><span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">GetWanIpAddress</span><span class="hljs-params">()</span></span> (*<span class="hljs-type">string</span>, <span class="hljs-type">error</span>) &#123;<br>	<span class="hljs-keyword">var</span> requestURL <span class="hljs-type">string</span><br>	requestURL = <span class="hljs-string">&quot;https://ipv4.jsonip.com&quot;</span><br>	<span class="hljs-comment">// 访问并获取公网IP地址</span><br>	resp, err := http.Get(requestURL)<br>	<span class="hljs-comment">// 方法执行完后关闭访问的body对象</span><br>	<span class="hljs-keyword">defer</span> <span class="hljs-function"><span class="hljs-keyword">func</span><span class="hljs-params">(Body io.ReadCloser)</span></span> &#123;<br>		err := Body.Close()<br>		<span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> &#123;<br>			log.Fatalf(<span class="hljs-string">&quot;获取IP地址的时候发生错误:%v&quot;</span>, err)<br>		&#125;<br>	&#125;(resp.Body)<br>	<span class="hljs-comment">// 如果发生错误则直接返回错误信息</span><br>	<span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> &#123;<br>		<span class="hljs-keyword">return</span> <span class="hljs-literal">nil</span>, err<br>	&#125;<br>	<span class="hljs-comment">// 读取body当中的所有信息</span><br>	result, err := io.ReadAll(resp.Body)<br>	<span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> &#123;<br>		<span class="hljs-keyword">return</span> <span class="hljs-literal">nil</span>, err<br>	&#125;<br>	<span class="hljs-comment">// 将返回的内容转换为json</span><br>	<span class="hljs-keyword">var</span> ipResponse = &amp;WanIpResponse&#123;&#125;<br>	err = json.Unmarshal(result, ipResponse)<br>	<span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> &#123;<br>		<span class="hljs-keyword">return</span> <span class="hljs-literal">nil</span>, err<br>	&#125;<br>	<span class="hljs-keyword">return</span> &amp;ipResponse.Ip, <span class="hljs-literal">nil</span><br>&#125;<br><br></code></pre></td></tr></table></figure>
                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/go/" class="category-chain-item">go</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/go/" class="print-no-link">#go</a>
      
        <a href="/tags/ddns/" class="print-no-link">#ddns</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>go实现阿里云DDNS</div>
      <div>https://hexo.xy94.top/2022/go实现阿里云DDNS.html</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>z</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年9月22日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/jwt.html" title="jwt">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">jwt</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/%E5%A4%9A%E6%95%B0%E6%8D%AE%E6%BA%90.html" title="多数据源">
                        <span class="hidden-mobile">多数据源</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.4/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.20.1/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>

  <script defer src="/js/leancloud.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
